package com.example.secondhandshop.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.example.secondhandshop.R;
import com.example.secondhandshop.ui.activity.Message_center;
import java.util.List;

public class MessageconterAdapter  extends ArrayAdapter<Message_center>{
        private List<Message_center> Messagescenter_data;
        private Context context;
        private int resourceId;

        public MessageconterAdapter(Context context, int resourceId, List<Message_center> data) {
            super(context, resourceId, data);
            this.context = context;
            this.Messagescenter_data = data;
            this.resourceId = resourceId;
        }

        class ViewHolder {
            TextView tvName;
            TextView tvContent;
            ImageView ivImage;
            TextView tvUnread;
            TextView tvTime;
        }
        public View getView(int position, View convertView, ViewGroup parent) {
            Message_center messageCenter = getItem(position);
            View view;
            final ViewHolder vh;
            if (convertView == null) {
                view = LayoutInflater.from(getContext()).inflate(resourceId, parent, false);
                vh = new ViewHolder();
                vh.ivImage=view.findViewById(R.id.send_userimage);
                vh.tvName=view.findViewById(R.id.send_user);
                vh.tvContent=view.findViewById(R.id.send_massage);
                vh.tvTime=view.findViewById(R.id.send_time);
                vh.tvUnread=view.findViewById(R.id.unread_message);
                view.setTag(vh);
            } else {
                view = convertView;
                vh = (ViewHolder) view.getTag();
            }
            vh.tvName.setText(messageCenter.getName());
            vh.tvContent.setText(messageCenter.getNewcontent());
            vh.tvTime.setText(messageCenter.getNewtime());
            vh.tvUnread.setText(messageCenter.getUnreed());
            Glide.with(context).load(messageCenter.getUrl()).into(vh.ivImage);
            return view;
        }
}
